package PrimitiveDataStructures;

import java.util.*;


/**
 * 
 * An implementation of a hash table key-value associative map data structure.
 * 
 * @author Yevgeny Levanzov & Daniel Samuelov
 *
 */
public class MyHashTable<K,V> implements KeyValueDataStructure<K,V> {

	private Hashtable<K,V> htable;

	
	/**
	 * Default constructor.
	 * 
	 */
	public MyHashTable() {
		
		this.htable = new Hashtable<K,V>();
	}
	
	
	/* (non-Javadoc)
	 * @see PrimitiveDataStructures.KeyValueDataStructure#size()
	 */
	public int size() {
		
		return this.htable.size();
	}
	

	/* (non-Javadoc)
	 * @see PrimitiveDataStructures.KeyValueDataStructure#isEmpty()
	 */
	public boolean isEmpty() {
		
		return this.htable.isEmpty();
	}
	
	

	/* (non-Javadoc)
	 * @see PrimitiveDataStructures.KeyValueDataStructure#containsKey(java.lang.Object)
	 */
	public boolean containsKey(K key) {
		
		return this.htable.containsKey(key);
	}
	

	/* (non-Javadoc)
	 * @see PrimitiveDataStructures.KeyValueDataStructure#get(java.lang.Object)
	 */
	public V get(K key) {
		
		return this.htable.get(key);
	}
	

	/* (non-Javadoc)
	 * @see PrimitiveDataStructures.KeyValueDataStructure#put(java.lang.Object, java.lang.Object)
	 */
	public void put(K key, V value) {
		
		this.htable.put(key, value);
	}

	
	/* (non-Javadoc)
	 * @see PrimitiveDataStructures.KeyValueDataStructure#keySet()
	 */
	public Set<K> keySet() {
		
		return this.htable.keySet();
	}
	

	/* (non-Javadoc)
	 * @see PrimitiveDataStructures.KeyValueDataStructure#remove(java.lang.Object)
	 */
	public void remove(K key) {
		
		this.htable.remove(key);
	}
	
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		
		String s = "[";
		
		for (Map.Entry<K,V> se : htable.entrySet()) {
			s = s + "-- " + se.getKey() + " --> " + se.getValue() + ", "; 
		}
		
		if (s.length() >= 2) {
			s = s.substring(0, s.length()-2);
		}
		
		s = s+ "]"; 
		
		return s;
	}
	

}
